QuickOPC User's Guide and Reference
Reading just the value (OPC Classic)
Development Models > Imperative Programming Model > Imperative Programming Model for OPC Data (Classic and UA) > Obtaining Information (OPC Data) > Reading from OPC Classic Items > Reading just the value (OPC Classic)
In This Topic

Some applications need the actual data value for further processing (e.g. for computations that need be performed on the values); in case the value does not have the Good quality, the computation cannot proceed (an error).

Some OPC Servers need time to provide valid data, and when you ask for a new item, they initially respond with "bad" or "uncertain" data quality. This can be a problem if your code makes a simple Read and expects a "good" quality. To overcome such situations, consider the extension methods described in Waiting for OPC-DA Items.

A single item

For such usage, call the ReadItemValue method, passing it the same arguments as to the ReadItem method. The method makes a Read, and tests whether the OPC item’s quality is Good. You will receive back an Object (a VARIANT in QuickOPC-COM) holding the actual data value. Iif the value obtained does not have a Good quality, the method returns an error.

Example 1

.NET

// This example shows how to read and display value of a single item.
// One of the shortest examples possible.

using System;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.OperationModel;

namespace DocExamples.DataAccess._EasyDAClient
{
    partial class ReadItemValue
    {
        public static void Main1()
        {
            // Instantiate the client object.
            var client = new EasyDAClient();

            Console.WriteLine("Reading item value...");
            object value;
            try
            {
                value = client.ReadItemValue("", "OPCLabs.KitServer.2", "Demo.Ramp");
            }
            catch (OpcException opcException)
            {
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message);
                return;
            }

            Console.WriteLine(value);
        }
    }
}
# This example shows how to read and display value of a single item.
# One of the shortest examples possible.

#requires -Version 5.1
using namespace OpcLabs.EasyOpc.DataAccess
using namespace OpcLabs.EasyOpc.OperationModel

# The path below assumes that the current directory is [ProductDir]/Examples-NET/PowerShell/Windows .
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcClassicCore.dll"
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcClassic.dll"
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcClassicComponents.dll"

# Instantiate the client object.
$client = New-Object EasyDAClient

Write-Host "Reading item value..."
try {
    $value = [IEasyDAClientExtension]::ReadItemValue($client, "", "OPCLabs.KitServer.2", "Demo.Ramp")
}
catch [OpcException] {
    Write-Host "*** Failure: $($PSItem.Exception.GetBaseException().Message)"
    return
}

Write-Host $value
# This example shows how to read value of a single item, and display it.

# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from OpcLabs.EasyOpc.DataAccess import *
from OpcLabs.EasyOpc.OperationModel import *


# Instantiate the client object
client = EasyDAClient()

print('Reading item value...')
try:
    value = IEasyDAClientExtension.ReadItemValue(client, '', 'OPCLabs.KitServer.2', 'Demo.Single')
except OpcException as opcException:
    print('*** Failure: ' + opcException.GetBaseException().Message)
    exit()

# Display results
print('value: ', value, sep='')
' This example shows how to read and display value of a single item.
' One of the shortest examples possible.

Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.OperationModel

Namespace DataAccess._EasyDAClient
    Partial Friend Class ReadItemValue
        Public Shared Sub Main1()
            Dim client As New EasyDAClient()

            Console.WriteLine("Reading item...")
            Try
                Console.WriteLine(client.ReadItemValue("", "OPCLabs.KitServer.2", "Demo.Ramp"))
            Catch opcException As OpcException
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message)
                Exit Sub
            End Try
        End Sub
    End Class
End Namespace

COM

// This example shows how to read value of a single item, and display it.

$Client = new COM("OpcLabs.EasyOpc.DataAccess.EasyDAClient");

try
{
    $value = $Client->ReadItemValue("", "OPCLabs.KitServer.2", "Simulation.Random");
}
catch (com_exception $e)
{
    printf("*** Failure: %s\n", $e->getMessage());
    Exit();
}

printf("value: %s\n", $value);
// This example shows how to read values of a single item, and display it.

var Client = new ActiveXObject("OpcLabs.EasyOpc.DataAccess.EasyDAClient");
var value = Client.ReadItemValue("", "OPCLabs.KitServer.2", "Simulation.Random");
WScript.Echo("value: " + value);
// This example shows how to read value of a single item, and display it.

class procedure ReadItemValue.Main;
var
  Client: OpcLabs_EasyOpcClassic_TLB._EasyDAClient;
  Value: OleVariant;
begin
  // Instantiate the client object
  Client := CoEasyDAClient.Create;

  try
    Value := Client.ReadItemValue('', 'OPCLabs.KitServer.2', 'Simulation.Random');
  except
    on E: EOleException do
    begin
      WriteLn(Format('*** Failure: %s', [E.GetBaseException.Message]));
      Exit;
    end;
  end;

  // Display results
  WriteLn('Value: ', Value);
end;
// This example shows how to read and display value of a single item.
// One of the shortest examples possible.

mle_outputtext.Text = ""

// Instantiate the client object
OLEObject client
client = CREATE OLEObject
client.ConnectToNewObject("OpcLabs.EasyOpc.DataAccess.EasyDAClient")

// Obtain value of a node
mle_outputtext.Text = mle_outputtext.Text + "Reading item value..." + "~r~n"
Any value
TRY
    value = client.ReadItemValue("", "OPCLabs.KitServer.2", "Demo.Ramp")
CATCH (OLERuntimeError oleRuntimeError)
    mle_outputtext.Text = mle_outputtext.Text + "*** Failure: " + oleRuntimeError.Description + "~r~n"
    RETURN
END TRY

// Display results
mle_outputtext.Text = mle_outputtext.Text + String(value) + "~r~n"
# This example shows how to read value of a single item, and display it.

# The Python for Windows (pywin32) extensions package is needed. Install it using "pip install pypiwin32".
# CAUTION: We now recommend using Python.NET package instead. Full set of examples with Python.NET is available!
import win32com.client
from pywintypes import com_error

# Instantiate the client object
client = win32com.client.Dispatch('OpcLabs.EasyOpc.DataAccess.EasyDAClient') 

# Perform the operation
try:
    value = client.ReadItemValue('', 'OPCLabs.KitServer.2', 'Demo.Single')
except com_error as e:
    print('*** Failure: ' + e.args[2][1] + ': ' + e.args[2][2])
    exit()

# Display results
print('value: ', value)
Rem This example shows how to read value of a single item, and display it.

Private Sub ReadItemValue_Main_Command_Click()
    OutputText = ""
    
    ' Instantiate the client object
    Dim client As New EasyDAClient

    On Error Resume Next
    Dim value
    value = client.ReadItemValue("", "OPCLabs.KitServer.2", "Simulation.Random")
    If Err.Number <> 0 Then
        OutputText = OutputText & "*** Failure: " & Err.Source & ": " & Err.Description & vbCrLf
        Exit Sub
    End If
    On Error GoTo 0

    ' Display results
    OutputText = OutputText & "Value: " & value & vbCrLf
End Sub
Rem This example shows how to read value of a single item, and display it.

Option Explicit

Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.DataAccess.EasyDAClient")
On Error Resume Next
Dim value: value = Client.ReadItemValue("", "OPCLabs.KitServer.2", "Simulation.Random")
If Err.Number <> 0 Then
    WScript.Echo "*** Failure: " & Err.Source & ": " & Err.Description
    WScript.Quit
End If
On Error Goto 0
WScript.Echo "value: " & value

Example 2

.NET

// This example shows how to read value of a single item, and display it, using CLSID instead of ProgID of the OPC Server.

using System;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.OperationModel;

namespace DocExamples.DataAccess._EasyDAClient
{
    partial class ReadItemValue
    {
        public static void CLSID()
        {
            // Instantiate the client object.
            var client = new EasyDAClient();

            Console.WriteLine("Reading item value...");
            object value;
            try
            {
                value = client.ReadItemValue("", "{C8A12F17-1E03-401E-B53D-6C654DD576DA}", "Simulation.Random");
            }
            catch (OpcException opcException)
            {
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message);
                return;
            }

            Console.WriteLine($"value: {value}");
        }
    }
}
# This example shows how to read value of a single item, and display it, using CLSID instead of ProgID of the OPC
# Server.

# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from OpcLabs.EasyOpc import *
from OpcLabs.EasyOpc.DataAccess import *
from OpcLabs.EasyOpc.OperationModel import *


# Instantiate the client object
client = EasyDAClient()

print('Reading item value...')
try:
    value = IEasyDAClientExtension.ReadItemValue(client,
                                                 '', '{C8A12F17-1E03-401E-B53D-6C654DD576DA}', 'Simulation.Random')
except OpcException as opcException:
    print('*** Failure: ' + opcException.GetBaseException().Message)
    exit()

# Display results
print('value: ', value, sep='')

COM

Rem This example shows how to read value of a single item, and display it, using CLSID instead of ProgID of the OPC Server.

Option Explicit

Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.DataAccess.EasyDAClient")
On Error Resume Next
Dim value: value = Client.ReadItemValue("", "{C8A12F17-1E03-401E-B53D-6C654DD576DA}", "Simulation.Random")
If Err.Number <> 0 Then
    WScript.Echo "*** Failure: " & Err.Source & ": " & Err.Description
    WScript.Quit
End If
On Error Goto 0
WScript.Echo "value: " & value

 

 

Reading an array

// Shows how to read an OPC item that is of array type.

using System;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.OperationModel;

namespace DocExamples.DataAccess._EasyDAClient
{
    partial class ReadItemValue
    {
        public static void Array()
        {
            // Instantiate the client object.
            var client = new EasyDAClient();

            Console.WriteLine("Reading array value...");
            int[] value;
            try
            {
                // UInt16 is returned as Int32, because UInt16 is not a CLS-compliant type (and is not supported in VB.NET).
                value = (int[])client.ReadItemValue("", "OPCLabs.KitServer.2", "Simulation.ReadValue_ArrayOfUI2");
            }
            catch (OpcException opcException)
            {
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message);
                return;
            }

            if (!(value is null))
            {
                Console.WriteLine(value[0]);
                Console.WriteLine(value[1]);
                Console.WriteLine(value[2]);
            }
        }
    }
}
# Shows how to read an OPC item that is of array type.

# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from OpcLabs.EasyOpc import *
from OpcLabs.EasyOpc.DataAccess import *
from OpcLabs.EasyOpc.OperationModel import *


# Instantiate the client object
client = EasyDAClient()

print('Reading array value...')
try:
    # UInt16 is returned as Int32, because UInt16 is not a CLS-compliant type (and is not supported in VB.NET).
    value = IEasyDAClientExtension.ReadItemValue(client, '', 'OPCLabs.KitServer.2', 'Simulation.ReadValue_ArrayOfUI2')
except OpcException as opcException:
    print('*** Failure: ' + opcException.GetBaseException().Message)
    exit()

# Display results
if value is not None:
    print(value[0])
    print(value[1])
    print(value[2])
' Shows how to read an OPC item that is of array type.

Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.OperationModel

Namespace DataAccess._EasyDAClient
    Partial Friend Class ReadItemValue
        Public Shared Sub Array()
            Dim client As New EasyDAClient()

            Console.WriteLine("Reading array value...")
            Dim value As Int32()
            Try
                ' UInt16 is returned as Int32, because UInt16 is not a CLS-compliant type (and is not supported in VB.NET).
                value = CType(client.ReadItemValue("", "OPCLabs.KitServer.2", "Simulation.ReadValue_ArrayOfUI2"), Int32())
            Catch opcException As OpcException
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message)
                Exit Sub
            End Try

            If Not IsNothing(value) Then
                Console.WriteLine(value(0))
                Console.WriteLine(value(1))
                Console.WriteLine(value(2))
            End If
        End Sub
    End Class
End Namespace

 

Reading from the device

// This example shows how to read a value of a single item from the device and display its value.

using System;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.OperationModel;

namespace DocExamples.DataAccess._EasyDAClient
{
    partial class ReadItemValue
    {
        public static void DeviceSource()
        {
            // Instantiate the client object.
            var client = new EasyDAClient();

            Console.WriteLine("Reading item value...");
            object value;
            try
            {
                // DADataSource enumeration:
                // Selects the data source for OPC reads (from device, from OPC cache, or dynamically determined).
                // The data source (memory, OPC cache or OPC device) selection is based on the desired value age and
                // current status of data received from the server.

                value = client.ReadItemValue("OPCLabs.KitServer.2", "Demo.Ramp", DADataSource.Device);
            }
            catch (OpcException opcException)
            {
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message);
                return;
            }

            Console.WriteLine(value);
        }
    }
}
# This example shows how to read a value of a single item from the device and display its value.

# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from OpcLabs.EasyOpc import *
from OpcLabs.EasyOpc.DataAccess import *
from OpcLabs.EasyOpc.OperationModel import *


# Instantiate the client object
client = EasyDAClient()

print('Reading item value...')
try:
    # DADataSource enumeration:
    # Selects the data source for OPC reads (from device, from OPC cache, or dynamically determined).
    # The data source (memory, OPC cache or OPC device) selection is based on the desired value age and
    # current status of data received from the server.
    value = IEasyDAClientExtension.ReadItemValue(client,
                                                 ServerDescriptor('OPCLabs.KitServer.2'),
                                                 DAItemDescriptor('Demo.Single'),
                                                 DAReadParameters(DADataSource.Device))
except OpcException as opcException:
    print('*** Failure: ' + opcException.GetBaseException().Message)
    exit()

# Display results
print('value: ', value, sep='')

Multiple items

For reading just the data values of multiple data values (with a test for Good quality) in an efficient manner, call the ReadMultipleItemValues method (instead of multiple ReadItemValue calls in a loop). You will receive back an array of ValueResult objects.

.NET

// This example shows how to read values of 4 items at once, and display them.

using System;
using System.Diagnostics;
using OpcLabs.BaseLib.OperationModel;
using OpcLabs.EasyOpc.DataAccess;

namespace DocExamples.DataAccess._EasyDAClient
{
    class ReadMultipleItemValues
    {
        public static void Main1()
        {
            // Instantiate the client object.
            var client = new EasyDAClient();

            ValueResult[] valueResults = client.ReadMultipleItemValues("OPCLabs.KitServer.2",
                new DAItemDescriptor[]
                {
                    "Simulation.Random", "Trends.Ramp (1 min)", "Trends.Sine (1 min)", "Simulation.Register_I4"
                });

            for (int i = 0; i < valueResults.Length; i++)
            {
                ValueResult valueResult = valueResults[i];
                Debug.Assert(!(valueResult is null));

                if (valueResult.Succeeded)
                    Console.WriteLine($"valueResults({i}).Value: {valueResult.Value}");
                else
                    Console.WriteLine($"valueResults({i}) *** Failure: {valueResult.ErrorMessageBrief}");
            }
        }


        // Example output:
        //
        //valueResults(0).Value: 0.00125125888851588
        //valueResults(1).Value: 0.732510924339294
        //valueResults(2).Value: -0.993968485238202
        //valueResults(3).Value: 0
    }
}
# This example shows how to read values of 4 items at once, and display them.

# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from OpcLabs.EasyOpc import *
from OpcLabs.EasyOpc.DataAccess import *
from OpcLabs.EasyOpc.DataAccess.OperationModel import *
from OpcLabs.EasyOpc.OperationModel import *


# Instantiate the client object.
client = EasyDAClient()

#
valueResultArray = IEasyDAClientExtension.ReadMultipleItemValues(client, [
    DAReadItemArguments(ServerDescriptor('OPCLabs.KitServer.2'), DAItemDescriptor('Simulation.Random')),
    DAReadItemArguments(ServerDescriptor('OPCLabs.KitServer.2'), DAItemDescriptor('Trends.Ramp (1 min)')),
    DAReadItemArguments(ServerDescriptor('OPCLabs.KitServer.2'), DAItemDescriptor('Trends.Sine (1 min)')),
    DAReadItemArguments(ServerDescriptor('OPCLabs.KitServer.2'), DAItemDescriptor('Simulation.Register_I4')),
    ])

for i, valueResult in enumerate(valueResultArray):
    assert valueResult is not None
    if valueResult.Succeeded:
        print('valueResultArray[', i, '].Value: ', valueResult.Value, sep='')
    else:
        print('valueResultArray[', i, '] *** Failure: ', valueResult.ErrorMessageBrief, sep='')
# This example shows how to read values of 4 items at once, and display them.

#requires -Version 5.1
using namespace OpcLabs.EasyOpc.DataAccess

# The path below assumes that the current directory is [ProductDir]/Examples-NET/PowerShell/Windows .
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcClassicCore.dll"
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcClassic.dll"
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcClassicComponents.dll"

# Instantiate the client object.
$client = New-Object EasyDAClient

$valueResults = [IEasyDAClientExtension]::ReadMultipleItemValues($client, 
    "OPCLabs.KitServer.2", @(
        (New-Object DAItemDescriptor("Simulation.Random")),
        (New-Object DAItemDescriptor("Trends.Ramp (1 min)")),
        (New-Object DAItemDescriptor("Trends.Sine (1 min)")),
        (New-Object DAItemDescriptor("Simulation.Register_I4"))
        ))

for ($i = 0; $i -lt $valueResults.Length; $i++) {
    $valueResult = $valueResults[$i]
    if ($valueResult.Succeeded) {
        Write-Host "valueResults($($i)).Value: $($valueResult.Value)"
    }
    else {
        Write-Host "valueResults($($i)) *** Failure: $($valueResult.ErrorMessageBrief)"
    }
}


# Example output:
#
#valueResults(0).Value: 0.00125125888851588
#valueResults(1).Value: 0.732510924339294
#valueResults(2).Value: -0.993968485238202
#valueResults(3).Value: 0

COM

// This example shows how to read values of 4 items at once, and display them.

class procedure ReadMultipleItemValues.Main;
var
  Arguments: OleVariant;
  Client: OpcLabs_EasyOpcClassic_TLB._EasyDAClient;
  I: Cardinal;
  ReadItemArguments1: _DAReadItemArguments;
  ReadItemArguments2: _DAReadItemArguments;
  ReadItemArguments3: _DAReadItemArguments;
  ReadItemArguments4: _DAReadItemArguments;
  ValueResult: _ValueResult;
  Results: OleVariant;
begin
  ReadItemArguments1 := CoDAReadItemArguments.Create;
  ReadItemArguments1.ServerDescriptor.ServerClass := 'OPCLabs.KitServer.2';
  ReadItemArguments1.ItemDescriptor.ItemID := 'Simulation.Random';

  ReadItemArguments2 := CoDAReadItemArguments.Create;
  ReadItemArguments2.ServerDescriptor.ServerClass := 'OPCLabs.KitServer.2';
  ReadItemArguments2.ItemDescriptor.ItemID := 'Trends.Ramp (1 min)';

  ReadItemArguments3 := CoDAReadItemArguments.Create;
  ReadItemArguments3.ServerDescriptor.ServerClass := 'OPCLabs.KitServer.2';
  ReadItemArguments3.ItemDescriptor.ItemID := 'Trends.Sine (1 min)';

  ReadItemArguments4 := CoDAReadItemArguments.Create;
  ReadItemArguments4.ServerDescriptor.ServerClass := 'OPCLabs.KitServer.2';
  ReadItemArguments4.ItemDescriptor.ItemID := 'Simulation.Register_I4';

  Arguments := VarArrayCreate([0, 3], varVariant);
  Arguments[0] := ReadItemArguments1;
  Arguments[1] := ReadItemArguments2;
  Arguments[2] := ReadItemArguments3;
  Arguments[3] := ReadItemArguments4;

  // Instantiate the client object
  Client := CoEasyDAClient.Create;

  TVarData(Results).VType := varArray or varVariant;
  TVarData(Results).VArray := PVarArray(
    Client.ReadMultipleItemValues(Arguments));

  // Display results
  for I := VarArrayLowBound(Results, 1) to VarArrayHighBound(Results, 1) do
  begin
      ValueResult := IInterface(Results[I]) as _ValueResult;

      if ValueResult.Succeeded then
        WriteLn('results(', i, ').Value: ', ValueResult.Value)
      else
        WriteLn('results(', i, ') *** Failure: ', ValueResult.ErrorMessageBrief);
  end;

  VarClear(Results);
  VarClear(Arguments);
end;
// This example shows how to read the values of 4 different items at once.

mle_outputtext.Text = ""

// Instantiate the client object
OLEObject client
client = CREATE OLEObject
client.ConnectToNewObject("OpcLabs.EasyOpc.DataAccess.EasyDAClient")

// Prepare arguments.

OLEObject readItemArguments1
readItemArguments1 = CREATE OLEObject
readItemArguments1.ConnectToNewObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments")
readItemArguments1.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
readItemArguments1.ItemDescriptor.ItemID = "Simulation.Random"

OLEObject readItemArguments2
readItemArguments2 = CREATE OLEObject
readItemArguments2.ConnectToNewObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments")
readItemArguments2.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
readItemArguments2.ItemDescriptor.ItemID = "Trends.Ramp (1 min)"

OLEObject readItemArguments3
readItemArguments3 = CREATE OLEObject
readItemArguments3.ConnectToNewObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments")
readItemArguments3.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
readItemArguments3.ItemDescriptor.ItemID = "Trends.Sine (1 min)"

OLEObject readItemArguments4
readItemArguments4 = CREATE OLEObject
readItemArguments4.ConnectToNewObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments")
readItemArguments4.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
readItemArguments4.ItemDescriptor.ItemID = "Simulation.Register_I4"

OLEObject readItemArgumentsList
readItemArgumentsList = CREATE OLEObject
readItemArgumentsList.ConnectToNewObject("OpcLabs.BaseLib.Collections.ElasticVector")
readItemArgumentsList.Add(readItemArguments1)
readItemArgumentsList.Add(readItemArguments2)
readItemArgumentsList.Add(readItemArguments3)
readItemArgumentsList.Add(readItemArguments4)

// Obtain values.
OLEObject valueResultList
valueResultList = client.ReadItemValueList(readItemArgumentsList)

// Display results
Int i
FOR i = 0 TO valueResultList.Count - 1
    OLEObject valueResult
    valueResult = valueResultList.Item[i]
    IF valueResult.Succeeded THEN
        mle_outputtext.Text = mle_outputtext.Text + "valueResult[" + String(i) + "].Value: " + String(valueResult.Value) + "~r~n"
    ELSE
        mle_outputtext.Text = mle_outputtext.Text + "valueResult[" + String(i) + "] *** Failure: " + valueResult.ErrorMessageBrief + "~r~n"
    END IF    
NEXT
Rem This example shows how to read values of 4 items at once, and display them.

Private Sub ReadMultipleItemValues_Main_Command_Click()
    OutputText = ""
    
    Dim readArguments1 As New DAReadItemArguments
    readArguments1.serverDescriptor.ServerClass = "OPCLabs.KitServer.2"
    readArguments1.ItemDescriptor.itemId = "Simulation.Random"
    
    Dim readArguments2 As New DAReadItemArguments
    readArguments2.serverDescriptor.ServerClass = "OPCLabs.KitServer.2"
    readArguments2.ItemDescriptor.itemId = "Trends.Ramp (1 min)"
    
    Dim readArguments3 As New DAReadItemArguments
    readArguments3.serverDescriptor.ServerClass = "OPCLabs.KitServer.2"
    readArguments3.ItemDescriptor.itemId = "Trends.Sine (1 min)"
    
    Dim readArguments4 As New DAReadItemArguments
    readArguments4.serverDescriptor.ServerClass = "OPCLabs.KitServer.2"
    readArguments4.ItemDescriptor.itemId = "Simulation.Register_I4"
    
    Dim arguments(3) As Variant
    Set arguments(0) = readArguments1
    Set arguments(1) = readArguments2
    Set arguments(2) = readArguments3
    Set arguments(3) = readArguments4

    ' Instantiate the client object
    Dim client As New EasyDAClient

    Dim results() As Variant
    results = client.ReadMultipleItemValues(arguments)

    ' Display results
    Dim i: For i = LBound(results) To UBound(results)
        Dim valueResult As valueResult: Set valueResult = results(i)
        If valueResult.Succeeded Then
            OutputText = OutputText & "results(" & i & ").Value: " & valueResult.value & vbCrLf
        Else
            OutputText = OutputText & "results(" & i & ") *** Failure: " & valueResult.ErrorMessageBrief & vbCrLf
        End If
    Next
End Sub
Rem This example shows how to read values of 4 items at once, and display them.

Option Explicit

Dim ReadItemArguments1: Set ReadItemArguments1 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments")
ReadItemArguments1.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ReadItemArguments1.ItemDescriptor.ItemID = "Simulation.Random"

Dim ReadItemArguments2: Set ReadItemArguments2 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments")
ReadItemArguments2.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ReadItemArguments2.ItemDescriptor.ItemID = "Trends.Ramp (1 min)"

Dim ReadItemArguments3: Set ReadItemArguments3 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments")
ReadItemArguments3.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ReadItemArguments3.ItemDescriptor.ItemID = "Trends.Sine (1 min)"

Dim ReadItemArguments4: Set ReadItemArguments4 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments")
ReadItemArguments4.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ReadItemArguments4.ItemDescriptor.ItemID = "Simulation.Register_I4"

Dim arguments(3)
Set arguments(0) = ReadItemArguments1
Set arguments(1) = ReadItemArguments2
Set arguments(2) = ReadItemArguments3
Set arguments(3) = ReadItemArguments4

Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.DataAccess.EasyDAClient")
Dim results: results = Client.ReadMultipleItemValues(arguments)

Dim i: For i = LBound(results) To UBound(results)
    Dim ValueResult: Set ValueResult = results(i)
    If ValueResult.Succeeded Then
        WScript.Echo "results(" & i & ").Value: " & ValueResult.Value
    Else
        WScript.Echo "results(" & i & ") *** Failure: " & ValueResult.ErrorMessageBrief
    End If
Next

 

In QuickOPC.NET, you can pass in a ServerDescriptor object and an array of DAItemDescriptor objects, or an array of DAItemArguments objects, to the ReadMultipleItemValues method.

Read parameters

It is possible to specify read parameters, such as the value age, or that the read should be performed from the cache, or directly from the device. For more information, see Reading from OPC Classic Items.

See Also

Knowledge Base

Installed Examples - Web

Installed Examples - WindowsForms

Installed Examples - WPF

Installed Examples - Console

Examples - OPC Data Access